<?php
defined('_JEXEC') or die('Restricted access'); 
 
jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

?>
<script type="text/javascript">
	//<![CDATA[
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save') {
			var flag = true;
            
            if (document.adminForm.o_code.value == "") {
                alert( 'Please select outlet!' );
                document.adminForm.o_code.focus();
                flag = false;
            }
            else if(document.adminForm.visit_date.value == "")
            {
                alert( 'Please choose visit date!' );
                document.adminForm.visit_date.focus();
                flag = false;
            }
            
            if(flag == true)
            {
                submitform( pressbutton );    
            }
		}
	}
</script>

<form  id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd&controller=mservices")?>" method="post" name="adminForm" >
	<?php echo JHtml::_('bootstrap.startTabSet', 'userinfo', array('active' => 'msevices_detail'));
	echo JHtml::_('bootstrap.addTab', 'userinfo', 'msevices_detail', 'Detail', true);   ?>
	<div class="row-fluid">
    
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Details')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Guest Name')?>:</label>
					</td>
					<td colspan="2">
						<?php
							if(!empty($this->user_info->f_name) || !empty($this->user_info->l_name)){
								$guest_name = $this->user_info->l_name." ".$this->user_info->f_name;
							}else{
								$guest_name = $this->data->guest_name ;
							}
						?>
						<input type="text" title="type" maxlength="25" size="25" value="<?php echo $guest_name ; ?>" id="guest_name" name="guest_name" class="guest_name"/> 
					</td>
					<td class="key">
						<label for="title"><?php echo JText::_('Outlet')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['outlets']; ?>
					</td>
				</tr>
				<tr>
					<td class="key" valign="top">
						<label for="title"><?php echo JText::_('Member Id')?>:</label>
					</td>
					<td colspan="2">
						<?php 
							if(!empty($this->user_info->member_id)){
								$vip_number = $this->user_info->member_id ;
							}else{
								$vip_number = $this->data->vip_number ;
							}
						?>
						<input type="text" title="type" maxlength="25" size="25" value="<?php echo $vip_number ; ?>" id="vip_number" name="vip_number" class="vip_number" />
					</td>
					<td class="key">
						<label for="title"><?php echo JText::_('Visit Date')?>:</label>
					</td>
					<td colspan="2">
						<?php 
							echo JHTML::_ ( 'calendar', ($this->data->visit_date != '') ? $this->data->visit_date : '', 'visit_date', 'visit_date', '%Y-%m-%d');
						?> 
					</td>
				</tr>
			</table>
			<table class="table table-striped adminlist">
				<tr>
                    <td class="key">
                        <label for="title"><?php echo JText::_('Meal Period')?>:</label>
                    </td>
                    <td colspan="2">
                        <?php echo $this->lists['meal_period']; ?> 
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        <label for="title">Top Spenders:</label>
                    </td>
                    <td colspan="2">
                        <input type="checkbox" value="1" <?php if($this->data->top_spender_date != '') echo 'checked="checked"'; ?> name="topspenders" id="topspenders" />
                        <div class="topspenders">
                            <?php 
                                echo JHTML::_ ( 'calendar', ($this->data->top_spender_date != '') ? $this->data->top_spender_date : '', 'top_spender_date', 'top_spender_date', '%Y-%m' );
                            ?>  
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        <label for="title">New Join Members:</label>
                    </td>
                    <td colspan="2">
                        <input type="checkbox" <?php if($this->data->new_join_member_date != '') echo 'checked="checked"'; ?> value="1" name="newjoinmember" id="newjoinmember" />
                        <div class="newjoinmember">
                            <?php 
                                echo JHTML::_ ( 'calendar', ($this->data->new_join_member_date != '') ? $this->data->new_join_member_date : '', 'new_join_member_date', 'new_join_member_date', '%Y-%m');
                            ?>                                  
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        <label for="title">Inactive Members:</label>
                    </td>
                    <td colspan="2">
                        <input type="checkbox" <?php if($this->data->inactive_member_date != '') echo 'checked="checked"'; ?> value="1" name="inactivemembers" id="inactivemembers" />
                        <div class="inactivemembers">
                            <?php 
                                echo JHTML::_ ( 'calendar', ($this->data->inactive_member_date != '') ? $this->data->inactive_member_date : '', 'inactive_member_date', 'inactive_member_date', '%Y-%m');
                            ?>  
                        </div>
                    </td>
                </tr>
				<tr>
                    <td class="key">
                        <label for="title">Daily Top Spenders:</label>
                    </td>
                    <td colspan="2">
                        <input type="checkbox" <?php if($this->data->daily_top_date != '') echo 'checked="checked"'; ?> value="1" name="daily_top_spender" id="daily_top_spender" />
                        <div class="daily_top_spender">
                            <?php 
                                echo JHTML::_ ( 'calendar', ($this->data->daily_top_date != '') ? $this->data->daily_top_date : '', 'daily_top_date', 'daily_top_date', '%Y-%m' );
                            ?>  
                        </div>
                    </td>
                </tr>
				<script type="text/javascript">
					var typeMember = "<?php echo ($this->data->member_type != '' ? $this->data->member_type : ''); ?>";
					if(typeMember != "") {
						typeMember = typeMember.split("_");
						jQuery("#topspenders").attr("checked", (typeMember[0] == 0 ? false : true));
						if(typeMember[0] == 0) {
							jQuery(".topspenders").hide();
						}
						jQuery("#newjoinmember").attr("checked", (typeMember[1] == 0 ? false : true));
						if(typeMember[1] == 0) {
							jQuery(".newjoinmember").hide();
						}
						
						jQuery("#inactivemembers").attr("checked", (typeMember[2] == 0 ? false : true));
						if(typeMember[2] == 0) {
							jQuery(".inactivemembers").hide();
						}
						jQuery("#daily_top_spender").attr("checked", (typeMember[3] == 0 ? false : true));
						if(typeMember[3] == 0) {
						
							jQuery(".daily_top_spender").hide();
						}
					}
					else {
						jQuery(".topspenders").hide();
						jQuery(".newjoinmember").hide();
						jQuery(".inactivemembers").hide();
						jQuery(".daily_top_spender").hide();
					}
					function addChangeEventDate(objName) {
						jQuery("#"+objName).change(function(){
							if(jQuery(this).attr("checked") == "checked"){
								jQuery("."+objName).show();
							} else {
								jQuery("."+objName).hide();
							}
						});   
					}
					addChangeEventDate("topspenders");
					addChangeEventDate("newjoinmember");
					addChangeEventDate("inactivemembers");
					addChangeEventDate("daily_top_spender");
				</script>
				<tr>
					<td class="key" valign='top'>
						<label for="title"><?php echo JText::_('Question')?>:</label>
					</td>
					<td colspan="2">
						<?php 
							echo $this->lists['questions'] ;
						?> 
					</td>
				</tr>
				<tr>
					<td class="key" valign="top">
						<label for="title"><?php echo JText::_('Answer')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['answer'] ?>
					</td>
				</tr>
				<tr>
					<td class="key" valign='top'>
						<label for="title"><?php echo JText::_('Follow Up')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['follow_up'] ?>
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	<?php 
	echo JHtml::_('bootstrap.endTab');
	if(!empty($this->user_info)):

			echo JHtml::_('bootstrap.addTab', 'userinfo', 'details', 'User Infomation', true); 
		?>
			<legend><?php echo JText::_('User Infomation')?></legend>
			<div class="row-fluid">
				<table class="table table-striped adminlist">
					<tr>
							<td><?php echo JText::_('Member ID') ;?></td>
							<td>:</td>
							<td><strong>
								<?php
									if(!empty($this->user_info->member_id)){
										echo $this->user_info->member_id;
									}
								?> 
								</strong>
							</td>
						</tr>
					<?php if(!empty($this->user_info->prefix)): ?>	
				
					<tr>
						<td><?php echo JText::_('Name') ;?></td>
						<td>:</td>
						<td><strong>
							<?php
								if(!empty($this->user_info->f_name) || !empty($this->user_info->l_name)){
									$guest_name = $this->user_info->f_name." ".$this->user_info->l_name ;
								}else{
									$guest_name = $this->data->guest_name ;
								}
								echo $this->user_info->prefix.' '.$guest_name ; 
							?> 
							</strong>
						</td>
					</tr>
					<?php endif; ?>
					<tr>
							<td><?php echo JText::_('Mobile') ;?></td>
							<td>:</td>
							<td>
								<?php
									
									if(!empty($this->user_info->phone)){
										echo $this->user_info->phone;
									}
									else if(!empty($this->user_info->referer_phone)){
										echo $this->user_info->referer_phone;
									}
									else {
										echo "User have not mobiphone";
									}
								?>	
							</td>
						</tr>
					<tr>
						<td><?php echo JText::_('Date of Birth') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo $this->user_info->dob ; 
							?> 
						</td>
					</tr>
					<?php if(!empty($this->job)): ?>
					<tr>
						<td><?php echo JText::_('Job Title') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->job) ? '' : $this->job ;
							?> 
						</td>
					</tr>
					<?php endif; ?>
					<tr>
						<td><?php echo JText::_('Member Joining Date') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo $this->user_info->created_date ; 
							?> 
						</td>
					</tr>
					<?php if(!empty($this->outlet->name)): ?>
					<tr>
						<td><?php echo JText::_('Outlet') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->outlet->name) ? '' : $this->outlet->name ; 
							?> 
						</td>
					</tr>
					<?php endif; ?>
					<tr>
						<td><?php echo JText::_('Current points balance') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo number_format($this->p_o_u->point, 0,'.',',');
							?> 
						</td>
					</tr>
					<tr>
						<td><?php echo JText::_('Total Spend') ;?></td>
						<td>:</td>
						<td>
							<?php
								//echo $this->p_o_u ; 
								echo number_format($this->user_info->total_spend, 0,'.',',');
							?> 
						</td>
					</tr>
				</table>
			</div>
	<?php echo JHtml::_('bootstrap.endTab');
	if(!empty($this->l_tran)):
		echo JHtml::_('bootstrap.addTab', 'userinfo', 'infotab', 'Last transaction', true);
	?>		<legend><?php echo JText::_('Last transaction')?></legend>
			<div class="row-fluid">	
				<table class="table table-striped ">
					<tr>
						<td><?php echo JText::_('Outlet') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo $this->l_tran_outlet->name ;
							?> 
						</td>
					</tr>
					<tr>
						<td><?php echo JText::_('Pax') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo $this->l_tran->pax ; 
							?> 
						</td>
					</tr>
					<tr>
						<td><?php echo JText::_('Food') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->food) ? '' : number_format($this->l_tran->food,0,'.',',') ; 
							?> 
						</td>
					</tr>
					<?php if(!empty($this->l_tran->beverage)): ?>
					<tr>
						<td><?php echo JText::_('Beverage') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->beverage) ? '' : number_format($this->l_tran->beverage,0,'.',',') ; 
							?> 
						</td>
					</tr>
					<?php endif; ?>
					<?php if(!empty($this->l_tran->liquor)): ?>
					<tr>
						<td><?php echo JText::_('Liquor') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->liquor) ? '' : number_format($this->l_tran->liquor,0,'.',','); 
							?> 
						</td>
					</tr>
					<?php endif; ?>
					<?php if(!empty($this->l_tran->other)): ?>
					<tr>
						<td><?php echo JText::_('Other') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->other) ? '' : $this->l_tran->other ; 
							?> 
						</td>
					</tr>
					<?php endif;?>
					<?php if(!empty($this->l_tran->discount)): ?>
					<tr>
						<td><?php echo JText::_('Discount') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->discount)?'':number_format($this->l_tran->discount,0,'.',','); 
							?> 
						</td>
					</tr>
					<?php endif;?>
					<tr>
						<td><?php echo JText::_('Net sale') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->netsale)?'':number_format($this->l_tran->netsale,0,'.',','); 
							?> 
						</td>
					</tr>
					<?php if(!empty($this->l_tran->sc)): ?>
					<tr>
						<td><?php echo JText::_('Services charges') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->sc)?'':number_format($this->l_tran->sc,0,'.',','); ; 
							?> 
						</td>
					</tr>
					<?php endif; ?>
					<?php if(!empty($this->l_tran->total)): ?>
					<tr>
						<td><?php echo JText::_('Total') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo empty($this->l_tran->total)?'':number_format($this->l_tran->total,0,'.',','); 
							?> 
						</td>
					</tr>
					<?php endif; ?>
					<tr>
						<td><?php echo JText::_('Date receipt') ;?></td>
						<td>:</td>
						<td>
							<?php //echo $this->l_tran->date_receipt."<br/>";
								echo empty($this->l_tran->date_receipt)?'':$this->l_tran->date_receipt; ; 
							?> 
						</td>
					</tr>
					<?php if(!empty($this->l_tran->pay_type )): ?>
					<tr>
						<td><?php echo JText::_('Pay type') ;?></td>
						<td>:</td>
						<td>
							<?php
								echo $this->l_tran->pay_type ; 
							?> 
						</td>
					</tr>
					<?php endif; ?>
				</table>
			</div>
				<?php echo JHtml::_('bootstrap.endTab'); ?>
	<?php endif; endif ; ?>
	<?php echo JHtml::_('bootstrap.endTabSet'); ?>
	
	<input type="hidden" name="handle_by" value="<?php echo $this->user->id;?>" />
	<input type="hidden" name="complain_flag" value="<?php echo $this->user_info->id ;?>" />
	<input type="hidden" name="forward" value="<?php echo $this->forward ; ?>" />
	<input type="hidden" name="controller" value="mservices" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->data->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
